<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/scripts/jquery-easyui-1.6.6/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="/scripts/jquery-easyui-1.6.6/themes/icon.css">
		<script type="text/javascript" src="/scripts/jquery-easyui-1.6.6/jquery.min.js"></script>
		<script type="text/javascript" src="/scripts/jquery-easyui-1.6.6/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="/scripts/jquery-easyui-1.6.6/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="/scripts/project.js"></script>
	</head>

	<body>
		<script type="application/javascript">
			var pid = localStorage.getItem("pid");
			$(function() {
				$('#module').datagrid({
					method: 'get',
					url: pro_url + '/modules?pid=' + pid,
					columns: [
						[{
								field: 'ck',
								checkbox: true
							},
							{
								field: 'mName',
								title: '模块名称',
								width: 120
							},
							{
								field: '',
								title: '',
								formatter: formatOper,
								width: 120
							}
						]
					]
				})
			})

			function formatOper(val, row, index) {
				return '<a href="#" rel="external nofollow" onclick="del(' + index + ')">删除</a>';
			}
		</script>
		<table id="module" class="easyui-datagrid" title="" style="width: 360px; height: 400px" data-options="rownumbers:true,singleSelect:true,pagination:true" toolbar="#mtoolbar">
		</table>
		<div id="mtoolbar">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增模块</a>
		</div>
		<div id="adddlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px" closed="true" buttons="#adddlg-buttons">
			<form id="ff">
				<div style="margin-bottom:20px">
					<input class="easyui-textbox" name="m_name" id="m_name" style="width:100%" data-options="label:'模块名:',required:true">
				</div>
			</form>
		</div>
		<div id="adddlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveM()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#adddlg').dialog('close')">取消</a>
		</div>

		<script type="application/javascript">
			function add() {
				$('#adddlg').dialog('open').dialog('setTitle', '新增测试轮次');
				$('#ff').form('clear');

			}

			function saveM() {
				$('#ff').form('submit', {
					onSubmit: function() {
						var mname = $('#m_name').val();
						var p_data = {
							pid: pid,
							mname: mname
						};
						$.ajax({
							type: "post",
							url: "module/add",
							async: true,
							dataType: "json",
							data: JSON.stringify(p_data),
							success: function(data) {
								console.log(data),
									$('#module').datagrid('reload')
							}
						});
					}
				});
				$('#adddlg').dialog('close')
			}
			
			function del(index){
				$('#module').datagrid('selectRow',index);
				var row=$('#module').datagrid('getSelected');
				console.log(row)
				$.ajax({
					type:"get",
					url:"/module/del?pid="+row.pid+"&mid="+row.id,
					async:true,
					success:function(data){
						console.log(data)
						$('#module').datagrid('reload')
					}
				});
			}
		</script>
	</body>

</html>